/*
http 服务器封装
*/

#ifndef HTTP_SERVER_H 
#define HTTP_SERVER_H 

#include "../tcp_server.h"
#include "http_session.h"
#include "servlet.h"

namespace framework
{
namespace http
{

//http 服务器    
class HttpServer: public framework::TcpServer
{
public:
using ptr = std::shared_ptr<HttpServer>;

    /**
     * @brief 构造函数
     * @param[in] keepalive 是否长连接
     * @param[in] worker 工作调度器
     * @param[in] accept_worker 接收连接调度器
     */
    HttpServer(bool keepalive = false
                ,framework::IOManager* worker = framework::IOManager::GetThis()
                ,framework::IOManager* io_worker = framework::IOManager::GetThis()
                ,framework::IOManager* accept_worker = framework::IOManager::GetThis());

    //获取ServletDispatch
    ServletDispatch::ptr getServletDispatch() const { return m_dispatch;}

    //设置ServletDispatch
    void setServletDispatch(ServletDispatch::ptr v) { m_dispatch = v;}


    //设置服务器名称
    virtual void setName(const std::string& v) override;
protected:

    //客户端连接成功的回调函数  处理新连接的Socket类
    virtual void handleClient(Socket::ptr client) override;

private:
    bool m_isKeepalive;                 //是否保持长连接
    ServletDispatch::ptr m_dispatch;    //Servlet分发器
};



} // namespace http
} // namespace framework



#endif	/* HTTP_SERVER_H */
